package emulator.unittest.hardware.memory;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.memory.DebugMemoryBlock;
import emulator.hardware.memory.UnmappedMemoryException;

public class DebugMemoryBlockTest {

	@Test
	public void testDebugMemoryBlockReadFirst() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		assertEquals(0, memory.read(0));
	}

	@Test
	public void testDebugMemoryBlockReadLast() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		assertEquals(0, memory.read(0xFFF));
	}

	@Test(expected= UnmappedMemoryException.class)
	public void testDebugMemoryBlockReadOver() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		memory.read(0x1000);
	}

	@Test
	public void testDebugMemoryBlockReadBackFirst() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		memory.write(0, 0x55);
		assertEquals(0x55, memory.read(0));
	}

	@Test
	public void testDebugMemoryBlockReadBackLast() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		memory.write(0xFFF, 0x55);
		assertEquals(0x55, memory.read(0xFFF));
	}

	@Test(expected= UnmappedMemoryException.class)
	public void testDebugMemoryBlockWriteOver() throws EmulatorException {
		DebugMemoryBlock memory = new DebugMemoryBlock(0x1000);
		memory.write(0x1000, 0x55);
	}

}
